import 'package:cream_chat_flutter/assets/Icons.dart';
import 'package:cream_chat_flutter/navigator/HiNavigator.dart';
import 'package:cream_chat_flutter/navigator/Routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:cream_chat_flutter/globals/ThemeProvider.dart';

import 'IndexProvider.dart';

///路由页 引导页，需要继承Page
class IndexPage extends Page {
  const IndexPage({
    LocalKey key,
    String name,
  }) : super(key: key, name: name);

  Route createRoute(BuildContext context) => MaterialPageRoute(
        settings: this,
        builder: (BuildContext context) => ChangeNotifierProvider(
            create: (context) => IndexProvider(), child: Index()),
      );
}

class Index extends StatefulWidget {
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index> {
  void _incrementCounter() async {
    // GetTencentCosStsDto dto = await Ajax().getTencentCosStsDto();
    // if (dto == null) return;
    // print(dto.data.domain);
    IndexProvider ip = context.read<IndexProvider>();
    ip.add();
    ThemeProvider tp = context.read<ThemeProvider>();
    if (ip.count % 2 == 1) {
      tp.setThemeMode(ThemeMode.dark);
    } else {
      tp.setThemeMode(ThemeMode.light);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Consumer2(
        builder: (BuildContext context, ThemeProvider tp, IndexProvider ip,
                Widget child) =>
            Scaffold(
              appBar: AppBar(
                title: tp.Title("奶油聊天"),
              ),
              body: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    tp.NmText('You have pushed the button this many times:'),
                    tp.LgText('${ip.count}'),
                    Container(
                      width: 300,
                      height: 100,
                      decoration: tp.NmBoxDecoration(),
                      child: tp.LgText("你好"),
                    ),
                    getManIcon(),
                    getCateIcon(),
                    getExerciseIcon(),
                    getHeartBeatIcon(),
                    getMusicIcon(),
                    getQuestionIcon(),
                    getTagCircleIcon(),
                    getUsualPlaceIcon(),
                    getBookIcon(),
                    getIntimacyIcon(),
                    Padding(
                        padding: EdgeInsets.all(30),
                        child: GestureDetector(
                            onTap: () {
                              HiRouteDelegate.of(context)
                                  .replaceAll(Routes.bottomNavigator);
                            },
                            child: tp.NmText("去首页tab页"))),
                    Padding(
                        padding: EdgeInsets.all(30),
                        child: GestureDetector(
                            onTap: () {
                              HiRouteDelegate.of(context)
                                  .push(Routes.myDetails);
                            },
                            child: tp.NmText("去我的主页"))),
                    Padding(
                        padding: EdgeInsets.all(30),
                        child: GestureDetector(
                            onTap: () {
                              HiRouteDelegate.of(context)
                                  .push(Routes.userDetails);
                            },
                            child: tp.NmText("去用户详情页"))),
                    Padding(
                        padding: EdgeInsets.all(30),
                        child: GestureDetector(
                            onTap: () {
                              HiRouteDelegate.of(context).push(Routes.test);
                            },
                            child: tp.NmText("去测试页面"))),
                  ],
                ),
              ),
              floatingActionButton: FloatingActionButton(
                onPressed: _incrementCounter,
                tooltip: 'Increment',
                child: Icon(Icons.add),
              ),
            ));
  }
}
